﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_FindBlurSellInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 42)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if (!IsPostBack)
        {
            TarreOA.TarreOAModels.User user = (User)Session["user"];
            if (user.ShellManager == 1)
            {
                Label2.Text = "新建销售记录（销售记录总数 " + SellInfoManager.CountAllSellInfo() + " ）";
                lblShellUser.Visible = true;
                txtShellUser.Visible = true;
                Button3.Visible = true;
            }
            else
            {
                Label2.Text = "新建销售记录（销售记录总数 " + SellInfoManager.CountAllSellInfo(user.UserId) + " ）";
                lblShellUser.Visible = false;
                txtShellUser.Visible = false;
                Button3.Visible = false;
            }
        }
    }
    protected void Button2_Click(object sender, ImageClickEventArgs e)
    {
        TarreOA.TarreOAModels.User user = (User)Session["user"];
        int type = 0;
        if (user.ShellManager == 1)
        {
            type = 3;
        }
        SellInfo shellInfo = new SellInfo();
        if (txtShellUser.Text != "" && hidUserId.Value !="")
        {
            TarreOA.TarreOAModels.User u = new User();
            u.UserId = Convert.ToInt32(hidUserId.Value);
            shellInfo.ShellUser = u;
            type = 1;
        }
        else
        {
            shellInfo.ShellUser = user;
        }
        if (hidClientId.Value !="")
        {
            TarreOA.TarreOAModels.Client client = new Client();
            client.ClientId = Convert.ToInt32(hidClientId.Value);
            shellInfo.Client = client;
        }
        if (hidProductId.Value !="")
        {
            Product product = new Product();
            product.Productid = Convert.ToInt32(hidProductId.Value);
            shellInfo.Product = product;
        }
        if (txtSellDate.Text !="")
        {
            shellInfo.SellDate = Convert.ToDateTime(txtSellDate.Text);
        }
        if (txtCount.Text !="")
        {
            try
            {
                shellInfo.Count = Convert.ToInt32(txtCount.Text);
            }
            catch 
            {
            }
        }
        if (txtAgio.Text !="")
        {
            try
            {
                shellInfo.Agio = Convert.ToInt32(txtAgio.Text);
            }
            catch
            {
            }  
        }
        if (txtConsignmentUser.Text !="")
        {
            shellInfo.ConsignmentUser = txtConsignmentUser.Text;
        }
        if (txtRemark.Text !="")
        {
            shellInfo.Remark = txtRemark.Text;
        }
        Session["shellInfo"] = shellInfo;
        Response.Redirect("ShowShellInfo.aspx?type="+type.ToString());
    }
}
